<!--计量单位选择框-->
<template>
  <div>
    <BasicModal
      v-bind="config"
      @register="register"
      :title="modalTitle"
      width="800px"
      @ok="handleOk"
      destroyOnClose
      @visible-change="visibleChange"
    >
      <BasicTable
        :columns="columns"
        v-bind="$attrs"
        :useSearchForm="true"
        :formConfig="formConfig"
        :api="finalAssemblyPlanOrderQGXList"
        :searchInfo="searchInfo"
        :rowSelection="rowSelection"
        :indexColumnProps="indexColumnProps"
      ></BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, unref } from "vue";
import { BasicModal, useModalInner } from "/@/components/Modal";
import { finalAssemblyPlanOrderQGXList } from "./base.api";
import { createAsyncComponent } from "/@/utils/factory/createAsyncComponent";
import { useSelectBiz } from "/@/components/Form/src/jeecg/hooks/useSelectBiz";
import { selectProps } from "/@/components/Form/src/jeecg/props/props";
import { useAttrs } from "/@/hooks/core/useAttrs";

export default defineComponent({
  name: "CalculateSelectModal",
  components: {
    //此处需要异步加载BasicTable
    BasicModal,
    BasicTable: createAsyncComponent(
      () => import("/@/components/Table/src/BasicTable.vue"),
      {
        loading: true,
      }
    ),
  },
  props: {
    ...selectProps,
    //选择框标题
    modalTitle: {
      type: String,
      default: "前工序排产列表选择",
    },
    multiple: {
      type: Boolean,
      default: false,
    },
  },

  emits: ["register", "getSelectResult"],
  setup(props, { emit }) {
    let type: number = 0;
    //注册弹框
    const [register, { closeModal }] = useModalInner(async (data) => {
      type = data.type;
    });
    const attrs = useAttrs();
    //表格配置
    const config = {
      canResize: false,
      bordered: true,
      size: "small",
      rowKey: unref(props).rowKey,
      isRadioSelection: !(props.multiple == true) ?? true,
      // 请求之前对参数做处理
      beforeFetch(params) {
        // console.log("params",params);
      },
    };
    const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
    const [
      { rowSelection, indexColumnProps, visibleChange, getSelectResult },
    ] = useSelectBiz(finalAssemblyPlanOrderQGXList, getBindValue);
    rowSelection.columnWidth = 50;
    indexColumnProps.width = 50;
    const searchInfo = ref(props.params);

    //查询form
    const formConfig = {
      labelWidth: 80,
      baseColProps: {
        xs: 11,
        sm: 11,
      },
      schemas: [
        {
          label: "创建日期",
          field: "createTime",
          component: "RangePicker",
          componentProps: {
            valueType: "Date",
            getPopupContainer: () => document.body,
          },
          colProps: { span: 11 },
        },
        {
          label: "MO号",
          field: "moU9No",
          component: "JInput",
          colProps: { span: 11 },
        },
        {
          label: "PO号",
          field: "poNo",
          component: "JInput",
          colProps: { span: 11 },
        },
      ],
    };
    //定义表格列
    const columns = [
      {
        title: "MO号",
        dataIndex: "moU9No",
        width: 140,
        align: "left",
      },
      {
        title: "PO号",
        dataIndex: "poNo",
        width: 140,
      },
      {
        title: "图号",
        dataIndex: "drawingNo",
        width: 120,
      },
      {
        title: "班组名称",
        dataIndex: "eqptDesc",
        sorter: true,
        width: 120,
      },
      {
        title: "班组编号",
        dataIndex: "eqptCode",
        sorter: true,
        width: 140,
      },
      {
        title: "物料名称",
        dataIndex: "partName",
        width: 140,
      },
      {
        title: "物料号",
        dataIndex: "partCode",
        width: 140,
      },
      {
        title: "规格",
        dataIndex: "partSpec",
        width: 100,
      },
      {
        title: "制造提前期",
        dataIndex: "prodLeadTime",
        width: 120,
      },
      {
        title: "计划开始时间",
        dataIndex: "planStartTime",
        width: 160,
      },
      {
        title: "计划结束时间",
        dataIndex: "planEndTime",
        width: 160,
      },
      {
        title: "实际开始时间",
        dataIndex: "actualStartTime",
        width: 160,
      },
      {
        title: "实际结束时间",
        dataIndex: "actualEndTime",
        width: 140,
      },
      {
        title: "U9开工时间",
        dataIndex: "u9StartTime",
        width: 180,
      },
      {
        title: "工段",
        dataIndex: "sectionDesc",
        width: 100,
      },
      {
        title: "计划产量",
        dataIndex: "planQTy",
        width: 100,
      },
      {
        title: "完工数量",
        dataIndex: "finishedQty",
        width: 100,
      },
      {
        title: "未完工数量",
        dataIndex: "notFinishQty",
        width: 100,
      },
      {
        title: "创建人",
        dataIndex: "employeeName",
        width: 100,
      },
      {
        title: "创建人工号",
        dataIndex: "usrLogin",
        width: 100,
      },
      {
        title: "备注1",
        dataIndex: "comment1",
        width: 100,
      },
      {
        title: "备注2",
        dataIndex: "comment2",
        width: 100,
      },
    ];
    /**
     * 确定选择
     */
    function handleOk() {
      getSelectResult((options, values) => {
        //回传选项和已选择的值
        emit("getSelectResult", options, values, type);
        //关闭弹窗
        closeModal();
      });
    }

    return {
      config,
      handleOk,
      searchInfo,
      register,
      indexColumnProps,
      visibleChange,
      finalAssemblyPlanOrderQGXList,
      formConfig,
      getBindValue,
      columns,
      rowSelection,
    };
  },
});
</script>
